package com.example.democrud.common.beans.converter;

import org.apache.poi.ss.formula.functions.T;
import org.springframework.beans.BeanUtils;
import org.springframework.context.annotation.Bean;

import java.util.ArrayList;
import java.util.Collection;
import java.util.Collections;
import java.util.List;

/**
 * @ClassName MyBeansUtils
 * @Author Administrator
 * @Date 2020/4/23   16:14
 */
public class BeanConverterUtils {
    public static <T ,R > List<R> converterList(List<T> source,R[] rs){
        ArrayList<R> target = new ArrayList<>();
        for (int i=0;i<source.size();i++){
            BeanUtils.copyProperties(source.get(i),rs[i]);
            target.add(rs[i]);
        }
        return target;
    }

    public static  <R,T> T converter(R r, T t){
        BeanUtils.copyProperties(r,t);
        return t;
    }

    public static <R,T> List<T> converterList(List<R> rs,  T t){
        List<T> ts = new ArrayList<>();
        for(int i=0;i<rs.size();i++){
            converter(rs.get(i),t);
            ts.add(t);
        }
        return ts;
    }
}
